package com.hanrui.android.fragment.message.audit.performance;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.PerformanceBizDetailBean;
import com.hanrui.android.net.contract.message.audit.performance.PerformanceBizDetailContract;
import com.hanrui.android.net.presenter.message.audit.performance.PerformanceBizDetailPresenter;

import butterknife.BindView;

/**
 * 绩效基本信息
 *
 */

public class PerformanceBizDetailFragment extends BaseFragment<PerformanceBizDetailPresenter> implements PerformanceBizDetailContract.View {
    @BindView(R.id.main_title)
    TextView mainTitle;
    @BindView(R.id.subhead_title)
    TextView subheadTitle;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.thing_title)
    TextView thingTitle;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.page_num)
    TextView pageNum;
    @BindView(R.id.ll_addview)
    LinearLayout lladdview;

    String taskId,procInsId,bizId;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_performancedetail;
    }

    @Override
    protected void initInjector() { mFragmentComponent.inject(this); }

    @Override
    protected void initView(View view) {

        taskId = getArguments().getString("taskId");
        procInsId = getArguments().getString("procInsId");
        bizId = getArguments().getString("bizId");

        mPresenter.performanceBizDetail(getActivity(),taskId,procInsId,bizId);

    }



    public static PerformanceBizDetailFragment newInstance(String taskId, String procInsId, String bizId) {
        PerformanceBizDetailFragment fragment = new PerformanceBizDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putString("taskId", taskId);
        bundle.putString("procInsId", procInsId);
        bundle.putString("bizId", bizId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void performanceBizDetail(final PerformanceBizDetailBean data) {

        if (null != data) {

            mainTitle.setText(data.getDetail().getUserName()+"的绩效审批");
            subheadTitle.setText(data.getDetail().getCreateDate());

            name.setText(data.getDetail().getUserName());
            thingTitle.setText(data.getDetail().getOfficeName());
            time.setText(data.getDetail().getUserType());
            pageNum.setText(data.getDetail().getCreateDate());


            if (null != data.getDetail().getPerformanceList() && data.getDetail().getPerformanceList().size() > 0) {

                lladdview.setVisibility(View.VISIBLE);
                String name = "";
                for (int i = 0; i < data.getDetail().getPerformanceList().size(); i++) {

                    if (!name.equals(data.getDetail().getPerformanceList().get(i).getProjectContent())) {

                        addViewItem(data.getDetail().getPerformanceList().get(i),true);

                    }else {

                        addViewItem(data.getDetail().getPerformanceList().get(i), false);
                    }

                    name = data.getDetail().getPerformanceList().get(i).getProjectContent();

                }

            		}

        }

    }


    //添加ViewItem
    private void addViewItem(final PerformanceBizDetailBean.DetailBean.PerformanceListBean bean,boolean isShow) {
        View hotelEvaluateView = View.inflate(getActivity(), R.layout.item_performancedetail, null);
        TextView minTitle = hotelEvaluateView.findViewById(R.id.min_title);
        TextView name = hotelEvaluateView.findViewById(R.id.name);
        TextView workContenttitle = hotelEvaluateView.findViewById(R.id.work_contenttitle);
        TextView workContent = hotelEvaluateView.findViewById(R.id.work_content);
        TextView carryTitle = hotelEvaluateView.findViewById(R.id.carry_title);
        TextView carry = hotelEvaluateView.findViewById(R.id.carry);
        TextView check = hotelEvaluateView.findViewById(R.id.check);
        TextView baseScore = hotelEvaluateView.findViewById(R.id.base_score);
        TextView selfScore = hotelEvaluateView.findViewById(R.id.self_score);

        if (isShow) {

            minTitle.setText(bean.getProjectContent());
            minTitle.setVisibility(View.VISIBLE);
        }else {
            minTitle.setVisibility(View.GONE);
        }

        name.setText(bean.getYearTarget());
        workContenttitle.setText(bean.getQuarter()+"目标");
        workContent.setText(bean.getQuarterTarget());
        carryTitle.setText(bean.getQuarter()+"完成情况");
        carry.setText(bean.getQuarterCompletion());
        check.setText(bean.getRules());
        baseScore.setText(bean.getBaseScore());
        selfScore.setText(bean.getSelfScore());


        lladdview.addView(hotelEvaluateView);
    }


}
